<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Relations\UserInfoTrait;

/**
 * 章节
 * 与课程多对一
 * @author Joker
 * id int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
	teaches_id int(11) NOT NULL COMMENT '课程编号，对应teaches_class表',
	`name` VARCHAR(255) NOT NULL COMMENT '章节名称',
	user_id int(10) not null comment '用户编号',
	price MEDIUMINT(8) NOT NULL DEFAULT 0 COMMENT '价格 默认为0 免费',
 */
class TeachesChapter extends Model
{
    use SoftDeletes,UserInfoTrait;
    
    protected $table="teaches_chapter";
    
    protected $fillable = ['id','teaches_id','name','price','user_id'];
    
    protected $dates = ['deleted_at'];
    
    /**
     * 获取章节下的所有 相关教程
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function contents() {
        return $this->hasMany('App\Models\TeachesContent','chapter_id','id');
    }
    
    /**
     * 获取 课程信息
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function teaches()
    {
        return $this->belongsTo('App\Models\Teaches');
    }
    
}